package com.wontube.core.conf;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import com.google.gson.Gson;
import com.wontube.client.extension.utils.FileUtils;

/**
 * 
 * @author yuechao
 * 
 * 服务器版本信息
 * 
 */
public class VersionInfo implements Serializable {
	private static final long serialVersionUID = 4539424923870173164L;
	
	private static final Logger logger = LoggerFactory.getLogger(VersionInfo.class);
	public static final VersionInfo versionInfo = new VersionInfo();

	private String version = "1.0.0";
	private String remark = "server 1.0.0";

	/**
	 * 获取版本号
	 * 
	 * @return
	 */
	public String getVersion() {
		return this.version;
	}

	/**
	 * 获取版本信息备注
	 * 
	 * @return
	 */
	public String getRemark() {
		return remark;
	}

	/**
	 * 初始化加载版本信息
	 */
	public void load(File file) {
		logger.info("begins loading versionInfo");
		String json = "";
		try {
			json = FileUtils.readAllText(file);
		} catch (IOException e) {
			logger.error(e.toString());
		}
		
		if ("".equals(json)) {
			logger.warn("failed loading versionInfo!");
			return;
		}
		
		Gson gson = new Gson();
		VersionInfo info = gson.fromJson(json, VersionInfo.class);
		this.version = info.version;
		this.remark = info.remark;

		logger.info("finished loading versionInfo");
	}
}
